extends "../cTDR/cTDR.gd"
func _info():
	pass

func _connect():
	._connect()

var norcnt:int = 0
var tlv = 0
var nlv = 0
var spw1 = 30.0
var spw2 = 3
var spw3 = 60.0
var exdmg = 16.0

func _extInit():
	._extInit()
	#chaName = "圣剑客·Lv[0]"
	lv = 4
	attCoe.atkRan = 3
	attCoe.atk = 19 / 8.5 * 2 / 4
	attCoe.maxHp = 500 / 112.5 / 4
	addCdSkill("sss",5)
	addCdSkill("sss1",9)
	addCdSkill("sss2",13)
	addSkillTxt("涂毒精通：普攻[击中后]带毒[毒：每秒造成(16+33%物攻)点特效伤害，持续3秒]")
	addSkillTxt("爆炸毒药：扔出一瓶爆炸毒药，造成<30+技能等级*10>%物攻伤害，并立刻引爆所有毒【cd:5秒】[color=#666666][未解锁][/color]")
	addSkillTxt("剧毒药剂：扔出一瓶剧毒药剂，立刻叠<3+技能等级>层毒，并增加4点每层毒的伤害【cd:9秒】[color=#666666][未解锁][/color]")
	addSkillTxt("反噬毒药：扔出一瓶反噬毒药，敌方攻击时若身上有毒，则遭到毒的反噬，造成<60+技能等级*5>%毒伤害，持续10秒【cd:13秒】[color=#666666][未解锁][/color]")
	addSkillTxt("[color=red]Tips:杀人会获得经验，战斗结束后会计算经验并升级;升级获得的属性和解锁的技能及等级全局有效")
	nlv = 0
	lvup()
	if skill3unlock:
		skillunlock(3)
	if skill2unlock:
		skillunlock(2)
	if skill1unlock:
		skillunlock(1)

func _onBattleStart():
	._onBattleStart()
	if sys.test:
		lvup()
		if !skill3unlock:
			#print("unlock3")
			skillunlock(3)

func _castCdSkill(id):
	._castCdSkill(id)
	if id == "sss" && aiCha != null && skill1unlock:
		cst("爆炸毒药","000000",position)
		skill1up()
		hurtChara(aiCha,att.atk*spw1,Chara.HurtType.PHY,Chara.AtkType.SKILL)
		for i in aiCha.buffs:
			if i.id == "b_d":
				var dmg = i.exdmg * int(i.life)
				hurtChara(aiCha,dmg,Chara.HurtType.PHY,Chara.AtkType.EFF)
				i.isDel = true
				yield(reTimer(0.01),"timeout")

	if id == "sss1" && aiCha != null && skill2unlock:
		cst("剧毒药剂","000000",position)
		skill2up()
		aiCha.addBuff(ctrl.b_d.new(spw2,exdmg+4 +att.atk *0.33))

	if id == "sss2" && aiCha != null && skill3unlock:
		cst("反噬毒药","000000",position)
		skill3up()
		aiCha.addBuff(BF.new(1,spw3))

func _onAtkChara(atkinfo):
	if atkinfo.atkType == Chara.AtkType.NORMAL && !atkinfo.isMiss && atkinfo.hitCha != self && atkinfo.atkCha == self:
		atkinfo.hitCha.addBuff(ctrl.b_d.new(1,exdmg + att.atk*0.33))
	._onAtkChara(atkinfo)
#战后计算经验
func _onBattleEnd():
	._onBattleEnd()
	yield(reTimer(0.01),"timeout")
	lvup()
	upAtt()
#升级改名改等级
func lvup():

	#if chaName.find("Lv[") == -1:
	#	nlv = 0
	#else:
	#	nlv = int(chaName.right(chaName.find("[")).left(2))
		
	if killNum >= 2:
		tlv = 1
	var e = 2
	var k = 3
	while(killNum >= e + k):
		tlv += 1
		e = e + k
		k += 1
	if sys.test:tlv = nlv + 1
	tlv = min(18,tlv)
	if tlv > nlv:
		upattadd(tlv,nlv)
		nlv = tlv
	chaName = "圣射手·Lv[" + str(nlv) + "]"
#升级修改属性
func upattadd(tlv,nlv):
	attAdd.atk += (tlv - nlv) * 5.3
	attAdd.maxHp += (tlv - nlv) * 70
	attAdd.spd += (tlv - nlv) * 0.02
	healCha(self,(tlv - nlv) * 10)
#修改技能1系数
func skill1up():
	spw1 = (30.0 + skill1lv * 10) / 100.0
#修改技能2系数
func skill2up():
	spw2 = 3 + skill2lv
#修改技能3系数
func skill3up():
	spw3 = (60.0 + skill3lv * 5) / 100.0
#技能3buff
class BF:
	extends Buff
	var spw
	func _init(lv,spw):
		attInit()
		life = lv * 10
		self.spw = spw
		isNegetive = true

	func _connect():
		masCha.connect("onAtkChara",self,"run")

	func run(atkinfo):
		if atkinfo.atkType != Chara.AtkType.EFF:
			var bf = masCha.hasBuff("b_d")
			if bf != null:
				masCha.hurtChara(masCha,bf.exdmg * spw,Chara.HurtType.REAL,Chara.AtkType.EFF)